package com.changgou.seckill.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.seckill.pojo.SecKillTime;
import com.changgou.seckill.service.SecKillTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/secKillTimer")
public class SecKillTimeController {
    @Autowired
    private SecKillTimeService secKillTimeService;


    @PostMapping("/{id}")
    public Result deleteId(@PathVariable("id") Integer id) {
        secKillTimeService.deleteId(id);
        return new Result(true, StatusCode.OK, "删除成功");
    }

    /**
     * 删除某个活动某个时间段的商品信息
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id){
        secKillTimeService.delete(id);
        return new Result(true, StatusCode.OK,"成功");
    }

    /**
     * 查询所有的时间段
     * @param
     * @return
     */
    @GetMapping("/selectTime")
    public Result selectTime(){
        List<SecKillTime> timeList = secKillTimeService.selectTime();
        return new Result(true, StatusCode.OK,"成功",timeList);
    }


    /**
     * 为活动时段添加商品
     * @param time_id
     * @param goods_ids
     * @return
     */
    @PostMapping("/addSeckillGoodsToTime/{time_id}")
    public Result addSeckillGoods(@PathVariable("time_id") Integer time_id,@RequestParam List<Integer> goods_ids) {
        secKillTimeService.addSeckillGoods(time_id,goods_ids);
        return new Result(true, StatusCode.OK, "新增成功");
    }

}
